package com.elitesland.core.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author Mir
 * @date 2018-11-08
 */
@ApiModel("分页")
@Data
@Accessors(chain = true)
@Builder
public class PagingVO<T> implements Serializable {

    private static final long serialVersionUID = -1683800405530086022L;

    @ApiModelProperty("总行数")
    @JsonProperty("total")
    private Long total = 0L;

    @ApiModelProperty("数据列表")
    @JsonProperty("records")
    private List<T> records = Collections.emptyList();

    public PagingVO() {
    }

    public PagingVO(long total, List<T> records) {
        this.total = total;
        this.records = records;
    }

    public PagingVO(IPage<T> page) {
        this.total = page.getTotal();
        this.records = page.getRecords();
    }

    @Override
    public String toString() {
        return "Paging{" +
                "total=" + total +
                ", records=" + records +
                '}';
    }
}
